﻿using System;
using System.Linq;
using Reviewer.Data;
using Reviewer.Entities;
using Reviewer.Entities.Services;
using System.Collections.Generic;

namespace Reviewer.Business.Services
{
    /// <summary>
    /// News Service
    /// </summary>
    internal class WriterService : BaseService, IWriterService, IWriterAdminService
    {
        internal WriterService() : base() { }

        #region methods (public)
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        public ICollection<Writer> Find()
        {
            return new WriterRepository().SelectAll();
        }

        public Writer Find(int writerId)
        {
            return new WriterRepository().SelectBy(writerId);
        }

        public ICollection<Writer> Find(string logonName)
        {
            return new WriterRepository().SelectByAlternateKey(logonName);
        }

        public Writer Save(Writer writer)
        {
            if (writer.Id < 1)
            {
                return new WriterRepository().Create(writer);
            }
            else
            {
                return new WriterRepository().Update(writer);
            }
        }

        #endregion
    }
}